//
//  main.cpp
//  boost_asio_tcp
//
//  Created by Constantine Mars on 5/16/13.
//  Copyright (c) 2013 Constantine Mars. All rights reserved.
//
//  This is example from Boost::Asio Tutorial that demonstrates work with Asio sockets:
//  http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/tutorial/tutdaytime1.html
//

#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
using boost::asio::ip::icmp;

int main(int argc, const char * argv[])
{
    try
    {
    
        boost::asio::io_service io_service;
        tcp::resolver resolver(io_service);
        tcp::resolver::query query("dtt.local", "daytime");
        tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
        
        //icmp socket test
        icmp::resolver resolver_i(io_service);
        icmp::resolver::query query_i("localhost", "");
        icmp::resolver::iterator iter = resolver_i.resolve(query_i);
        try {
            icmp::socket socket_i(io_service, icmp::v4());
            std::cout << "icmp::socket created successfully\n";
        }
        catch (std::exception& e)
        {
            std::cerr << "icmp::socket exception: \"" << e.what() << "\"\n";
        }
        
//        tcp::socket socket(io_service);
//        
//        boost::asio::connect(socket, endpoint_iterator);
//        
//        for (;;)
//        {
//            boost::array<char, 128> buf;
//            boost::system::error_code error;
//            
//            size_t len = socket.read_some(boost::asio::buffer(buf), error);
//            if (error == boost::asio::error::eof)
//                break; // Connection closed cleanly by peer.
//            else if (error)
//                throw boost::system::system_error(error); // Some other error.
//            
//            std::cout.write(buf.data(), len);
//        }
        
    }
    catch (std::exception& e)
    {
        std::cerr << e.what() << std::endl;
    }
    
    return 0;
}

